package com.sxf.core.validator;


import com.sxf.utils.IdCardUtils;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * 
 * @description: 手机验证实现
 * @author: zhangyb@ccccit.com.cn
 * @date: 2021年1月6日 下午2:53:14
 */
public class IsIdNoValidator implements ConstraintValidator<IsIdNo, String> {

	private boolean checkNull;

	@Override
	public void initialize(IsIdNo constraintAnnotation) {
		this.checkNull = constraintAnnotation.checkNull();
	}

	@Override
	public boolean isValid(String value, ConstraintValidatorContext context) {
		if(!checkNull && value == null) {
			return true;
		}
		
		if((value == null)) {
			return false;
		}
		return IdCardUtils.validateCard(value);
	}

}
